import logging

from config import BASE_HOST


class RechargeApi:

    def __init__(self, ses):
        # 接收session对象的变量
        self.ses = ses

    # 获取充值验证码接口
    def get_recharge_verify_code(self, num):
        '''

        :param num: 随机小数或整数
        :return:
        '''
        url = BASE_HOST + f"/common/public/verifycode/{num}"
        resp = self.ses.get(url)
        logging.info(f"获取图片验证码的响应状态码为{resp.status_code}")
        return resp

    # 充值接口
    def recharge(self,num_amount,type="chinapnrTrust",formStr="reForm",valicode="8888"):
        # 定义一个字典变量，用来接收请求体数据
        body_recharge = {"paymentType": type,
                         "amount": num_amount,
                         "formStr": formStr,
                         "valicode": valicode}
        url = BASE_HOST+"/trust/trust/recharge"
        resp = self.ses.post(url,data=body_recharge)
        logging.info(f"获取充值接口的响应体为{resp.json()}")
        return resp

    # 第三方充值接口
    def third_recharge(self,url,body):
        resp = self.ses.post(url,data=body)
        logging.info(f"获取第三方充值接口的响应体为{resp.text}")
        return resp

